function createLayoutForReports()
{
	/*uploadDocPageLayout = $("#contentDiv").layout({
	     west__paneSelector:	"#reportsFilter"
		,center__paneSelector:	"#reportResults"
		,spacing_open: 			5 
		,spacing_closed: 		5
		,resizable: 			false
		,position:				'top'
		,west__spacing_open:	0
		,west__spacing_closed:	0
		,west__size:			'auto'
	});*/
	
	 $("#periodStartDate").datepicker({dateFormat:'dd-mm-yy'});
	    $("#periodEndDate").datepicker({dateFormat:'dd-mm-yy'});
}
function getReports(formId){
	var options ={
			target: "#reportResults",
			type: 'post',
			data: {},
			success: showResponseForReports,
			iframe: true
	};
	$("#"+formId).ajaxSubmit(options); 
}
function showResponseForReports()
{
	alert("response");
}

function loadReportsPage(){
	$.blockUI();
	
	$.post('getReportsPage.htm',{data:'data'},function(data){
		$(mainContentDiv).empty().html(data);
		$.unblockUI();
	},"html");
}

function reportsTable()
{
	$.blockUI();
	
	var filterData = $("#submitFilterDetails").formSerialize();
	alert(filterData);
	
	$.post('loadReportsTable.htm',filterData,function(data){
			$(rolesTableDiv).empty().html(data);
			$.unblockUI();
	},"html");
	
	
}

function loadDepttForBUForReports(selectId,selectIdToPopulate){
	var buId = $("#"+selectId).val();
	$.getJSON(contextRoot + "getDepttForBU.htm",{buId:buId},function(jsonData){
		var options = '';
		var option2='';
		 var numOfOptions = jsonData.length;
		
		 if(numOfOptions > 0){
			 	options += '<option value="' + 0 + '">' + "ALL" + '</option>';
			 for (var i = 0; i < jsonData.length; i++) {
				 options += '<option value="' + jsonData[i].optionValue + '">' + jsonData[i].optionDisplay + '</option>';
			 }
			 	$("#"+selectIdToPopulate).empty().html(options);
		 }else{
			 $("#docDepttId").empty();
			  //alert("No Departments mapped to selected business unit.");
			 
		 }
		 if(buId == 0){
			 option2 += '<option value="' + 0 + '">' + "ALL" + '</option>';
			 $("#docDepttId").empty().html(option2);
			 
		 }	
		 if(buId == ""){
			 $("#docDepttId").empty();
		 }
	});
}

function loadDepttForBUForVaultBU(selectId,selectIdToPopulate){
	var buId = $("#"+selectId).val();
	$.getJSON(contextRoot + "getDepttForBU.htm",{buId:buId},function(jsonData){
		var options = '';
		var option2='';
		 var numOfOptions = jsonData.length;
		
		 if(numOfOptions > 0){
			 	options += '<option value="' + 0 + '">' + "ALL" + '</option>';
			 for (var i = 0; i < jsonData.length; i++) {
				 options += '<option value="' + jsonData[i].optionValue + '">' + jsonData[i].optionDisplay + '</option>';
			 }
			 $("#"+selectIdToPopulate).empty().html(options);	 
		 }else{
			 $("#docDepartmentId").empty();
			// alert("No Departments mapped to selected business unit.");
			 
		 }
		 if(buId == 0){
			 option2 += '<option value="' + 0 + '">' + "ALL" + '</option>';
			$("#docDepartmentId").empty().html(option2);
			 
		 }	
		 if(buId == ""){
			 $("#docDepartmentId").empty();
		 }
	});
}

function loadCategAndSubCategForReports(){
	$("#docTypeId").change(function(){
		//var docType = $("#docTypeId").val();
		loadDocCategoryForReports();
	});
	$("#docCategoryId").change(function(){
		loadDocSubCategoryForReports();
	});
	
}

function loadDocCategoryForReports(){
	var docType = $("#docTypeId").val();
	
	$.getJSON("fetchCategory.htm",{id: $(this).val(), ajax: 'true',parentlevel: docType}, function(j){
		 var options = '';
		 var options1 = '';
		 var options2 = '';
		 var numOfOptions = j.length;
		 
		 if(numOfOptions > 0){
			 	options += '<option value="' + 0 + '">' + "ALL" + '</option>';
		      for (var i = 0; i < j.length; i++) {
		        options += '<option value="' + j[i].optionValue + '">' + j[i].optionDisplay + '</option>';
		      }
		 }else{
			 //alert("No Categories available for selected document type.");
			 $("#docSubCategoryId").empty();
		 }
      $("#docCategoryId").html(options);
      if(numOfOptions > 0){
    	  loadDocSubCategoryForReports();
      }
      if(docType == 0){
    	 options1 += '<option value="' + 0 +'">' + "ALL" + '</option>';
	     options2 += '<option value="' + 0 +'">' + "ALL" + '</option>';
	     $("#docCategoryId").empty().html(options1);
	     $("#docSubCategoryId").empty().html(options2);
      }
    })	;
}

function loadDocSubCategoryForReports(){
	var docCat = $("#docCategoryId").val();
	$.getJSON("fetchSubCategory.htm",{ajax: 'true',parentlevel: docCat}, function(j){
		 var options = '';
		 var options1 = '';
		 var numOfOptions = j.length;
		 if(numOfOptions > 0){
			 	 options += '<option value="' + 0 + '">' + "ALL" + '</option>';
			 for (var i = 0; i < j.length; i++) {
				 options += '<option value="' + j[i].optionValue + '">' + j[i].optionDisplay + '</option>';
			 }
		 }else{
			 // alert("No Sub-Categories available for selected document category.");
		 }
	$("#docSubCategoryId").html(options);
		if(docCat == 0){
			options1 += '<option value="' + 0 +'">' + "ALL" + '</option>';
			$("#docSubCategoryId").empty().html(options1);
		}
    });	
	
}

function expiredDocReports(){
	$.blockUI();
	
	$.post('loadExpiredReports.htm',{data:'data'},function(data){
			$(mainContentDiv).empty().html(data);
			$.unblockUI();
	},"html");
}

function loadExpiredDocReportsTable(){
	$.blockUI();
	
	var formData = $("#expiredReports").formSerialize();
	
	$.post('fetchExpiredDocDataForReports.htm',formData,function(data){
			$("#expiredDocReports").empty().html(data);
			$.unblockUI();
	},"html");
}

function nearExpiryReports(){
	$.blockUI();
	
	$.post('loadDocsNearExpiryReports.htm',{data:'data'},function(data){
			$(mainContentDiv).empty().html(data);
			$.unblockUI();
	},"html");
}

function loadNearExpiryDocReportsTable(){
	$.blockUI();
	
	var formData = $("#nearExpiryReports").formSerialize();
	
	$.post('fetchNearExpiryDocDataForReports.htm',formData,function(data){
			$("#nearExpiryDocReports").empty().html(data);
	},"html");
	
	$.unblockUI();
}

function vaultDetailsReports(){
	$.blockUI();
	
	$.post('loadVaultDetailsReports.htm',{data:'data'},function(data){
			$(mainContentDiv).empty().html(data);
			$.unblockUI();
	},"html");
}

function loadVaultReportsTable(){
	$.blockUI();
	
	var formData = $("#vaultDetails").formSerialize();
	
	$.post('fetchVaultDetailsReports.htm',formData,function(data){
		$("#vaultReports").empty().html(data);
		$.unblockUI();
	},"html");
}